package com.sunfeng.n3;


import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic="c.TPTInterrupt")
 class TPTInterrupt {

    private Thread thread;



    public void  start(){
         thread = new Thread(() -> {
            while (true) {
                Thread thread = Thread.currentThread();

                if (thread.isInterrupted()) {
                    log.debug("料理后事");
                    break;
                }
                try {
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    thread.interrupt();
                }
            }
        }, "监控线程");
        thread.start();

    }
    public void  stop(){
        thread.interrupt();
    }


}

@Slf4j(topic="c.TestTPT")
public class  TestTPT{
    public static void main(String[] args) throws InterruptedException {
        TPTInterrupt interrupt = new TPTInterrupt();

        interrupt.start();

        log.debug("线程启动");
        TimeUnit.MILLISECONDS.sleep(3500);

        log.debug("中断");
        interrupt.stop();
    }

}
